/**
 * 
 */
package com.gragra.data;
import java.util.ArrayList;
import java.util.Iterator;
import com.gragra.sampling.ThreadedUniformAccess;
import com.gragra.structures.Structure;
/**
 * @author Christoph Teichmann
 * created Dec 26, 2012 6:13:30 PM
 * @version 0.1
 */
public class MixingCorpusBaseImplementation<Type extends Structure> extends CorpusBaseImplementation<Type>
		implements MixingCorpus<Type>
{
	/* (non-Javadoc)
	 * @see com.gragra.data.CorpusBaseImplementation#addData(com.gragra.structures.Structure)
	 */
	@Override
	public void addData(Type s)
	{
		super.addData(s);
		dataMixed.add(s);
	}
	/**
	 * 
	 */
	private final ArrayList<Type> dataMixed = new ArrayList<Type>();
	/* (non-Javadoc)
	 * @see com.gragra.data.MixingCorpus#mixingIterator()
	 */
	@Override
	public Iterator<Type> mixingIterator()
	{return this.dataMixed.iterator();}
	/* (non-Javadoc)
	 * @see com.gragra.data.MixingCorpus#mix()
	 */
	@Override
	public void mix(ThreadedUniformAccess tua,int number)
	{
		int length = dataMixed.size();
		int l = length / 2;
		for(int i=0;i<l;++i)
		{
			int other = tua.nextInt(number,0, length-1);
			Type s = this.dataMixed.get(i);
			this.dataMixed.set(i, this.dataMixed.get(other));
			this.dataMixed.set(other, s);
		}
	}
}